package com.atguli.server;

import com.atguli.server.Util.CryptUtil;
import com.opencsv.CSVWriter;
import com.opencsv.CSVWriterBuilder;
import com.opencsv.ICSVWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import static com.atguli.server.Requ.MyCryValue.getMyCryTokenList;

/**
 * @author DPF
 */
public class MyWriteCSV {
    public static void main(String[] args) {
//        String csvFile = "tokens.csv";
//        // 将数据写入 CSV 文件
//        try (CSVWriter writer = new CSVWriter(new FileWriter(csvFile))) {
//            List<String[]> data = getMyCryTokenList();
//            String[] headers = {"username","token"};
//            writer.writeAll(Collections.singleton(headers));
//            writer.writeAll(data); // 直接传递 List<String[]>
//            System.out.println("数据已成功写入 CSV 文件: " + csvFile);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
        String csvFile = "users.csv";
        // 将数据写入 CSV 文件
        try (CSVWriter writer = (CSVWriter) new CSVWriterBuilder(new FileWriter(csvFile))
                .withSeparator(',')
                .withQuoteChar(ICSVWriter.NO_QUOTE_CHARACTER)
                .withEscapeChar(ICSVWriter.DEFAULT_ESCAPE_CHARACTER)
                .build()) {

            List<String[]> users = new ArrayList<>();
            for (int i = 1; i <= 1010; i++) {
                String name = "hnzhzx0" + i;
                String[] user = new String[]{name, CryptUtil.cryptSm3("rvM2iePUN@cvB56AbtSEP2Zj4e4zGsJ", "123456zZ@")};
                users.add(user);
            }

            writer.writeAll(users); // 直接传递 List<String[]>
            System.out.println("数据已成功写入 CSV 文件: " + csvFile);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

